package rz.socket;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.Socket;

class Client {
    Socket socket;
    BufferedReader in;
    PrintWriter out;
    
    public Client() {
        try {
            System.out.println("Try to Connect to 127.0.0.1:20000");
            socket = new Socket("127.0.0.1", 20000);
            System.out.println("The Server Connected.");
            System.out.println("Please enter some Character: ");
            BufferedReader line = new BufferedReader(new InputStreamReader(System.in));
            out = new PrintWriter(socket.getOutputStream(), true);
            String str = null;
            in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
            while((str = in.readLine()) != null){
    			out.println(str);
    			out.flush();
    			System.out.println("向网络写入一条数据");
    		}
            
            out.close();
            in.close();
            socket.close();
        } catch(Exception ex) {
            ex.printStackTrace();
        }
    }
    
    public static void main(String[] args) {
        new Client();
    }
}